home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / pccts / nesting.g < prev    next >
Text File  |  1993-07-19  |  1KB  |  50 lines

  1. /* nesting.g
  2.  *
  3.  * example that uses DLG save and restore state functions to handle
  4.  * nested #include file specifications.
  5.  *
  6.  * Uses "fixed" version of dlgauto.h and dlgdef.h made available 2-26-93.
  7.  *
  8.  * Can create executable with:
  9.  *
  10.  * antlr nesting.g
  11.  * dlg -C2 parser.dlg scan.c
  12.  * cc -o nesting nesting.c err.c scan.c
  13.  */
  14. #header <<
  15.     #include "charbuf.h"
  16.     #define MAX_NESTING     10
  17.     extern struct dlg_state fstack[];
  18.     extern int fsp;
  19. >>
  20.  
  21. <<
  22. struct dlg_state fstack[MAX_NESTING];
  23. int fsp=0;
  24.  
  25. main() { ANTLR(inc(), stdin); }
  26. >>
  27.  
  28. #token "[\ \t]+"        <<zzskip();>>
  29. #token "\n"             <<zzskip(); zzline++;>>
  30. #token "@"              <<if ( fsp>0 ) {
  31.                             zzskip();
  32.                             zzrestore_dlg_state(&fstack[--fsp]);
  33.                         }
  34.                         >>
  35.  
  36. inc :   ( gunk )+
  37.     ;
  38.  
  39. gunk:   <<FILE *f;>>
  40.         (   "[a-z]+"    <<printf("%s\n", $1.text);>>
  41.         )+
  42.     |   "#include" "\"" "[a-z]+" "\""
  43.         <<
  44.         zzsave_dlg_state(&fstack[fsp++]);
  45.         f = fopen($3.text, "r");
  46.         if ( f==NULL ) fprintf(stderr, "cannot open %s", $3.text);
  47.         zzrdstream(f);
  48.         >>
  49.     ;
  50.